package com.crm.service.impl.followPlanManager;

import com.crm.dao.mapper.customMapper.followPlanManager.FollowPlanMapper;
import com.crm.model.entity.followPlanManager.CpFollowPlan;
import com.crm.model.qo.followPlanManager.CpFollowPlanQO;
import com.crm.model.vo.followPlanManager.CpFollowPlanVO;
import com.crm.model.vo.followPlanManager.FollowPlanContactListVO;
import com.crm.model.vo.followPlanManager.FollowPlanCountVO;
import com.crm.service.followPlanManager.FollowPlanDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @Author: chaifuyou
 * @date 2021/3/31 16:46
 */
@Service
public class FollowPlanDbServiceImpl implements FollowPlanDbService {
    @Autowired
    private FollowPlanMapper followPlanMapper;

    /**
     * 跟进计划列表
     * @return
     */
    @Override
    public List<CpFollowPlanVO> selectCustomerProductList(CpFollowPlanQO cpFollowPlanQO, String sortOrder, Integer dateUnit, Integer followUnit) {
        return followPlanMapper.selectCustomerProductList(cpFollowPlanQO,sortOrder,dateUnit,followUnit);
    }

    /**
     * 添加跟进计划
     * @param cpFollowPlan
     */
    @Override
    public void addFollowPlan(CpFollowPlan cpFollowPlan) {
        followPlanMapper.insertSelective(cpFollowPlan);
    }

    /**
     * 取消跟进计划
     * @param cpFollowPlanId
     * @return
     */
    @Override
    public void deleteFollowPlan(String cpFollowPlanId) {
        followPlanMapper.deleteFollowPlan(cpFollowPlanId);
    }

    /**
     * 取消跟进计划
     * @param cpFollowPlan
     * @return
     */
    @Override
    public void updateFollowPlan(CpFollowPlan cpFollowPlan) {
        followPlanMapper.updateByPrimaryKeySelective(cpFollowPlan);
    }

    /**
     * 统计日期的跟进情况
     * @param planDate
     * @return
     */
    @Override
    public List<Integer> getFollowPlanCount(String planDate,String accountId,String startDate,String endDate) {
        if (Objects.nonNull(planDate)){
            planDate =planDate.replaceAll("-","");
        }
        if (Objects.nonNull(startDate) && Objects.nonNull(endDate)){
            startDate =startDate.replaceAll("-","");
            endDate =endDate.replaceAll("-","");
        }
        return followPlanMapper.getFollowPlanCount(planDate,accountId,startDate,endDate);
    }

    /**
     * 当天跟进的客户列表
     * @param planDate
     * @param order
     * @param accountId
     * @return
     */
    @Override
    public List<FollowPlanContactListVO> getFollowPlanListByDate(String planDate, StringBuilder order, String accountId,Integer dateUnit) {
        return followPlanMapper.getFollowPlanListByDate(planDate,order,accountId,dateUnit);
    }

    /**
     * 根据客户获取一个联系人信息，取热度值最高的
     * @param customerId
     * @return
     */
    @Override
    public FollowPlanContactListVO getOneContactInfoByCustomerId(String customerId) {
        return followPlanMapper.getOneContactInfoByCustomerId(customerId);
    }

    /**
     * 根据id查询跟进信息
     * @param cpFollowPlanId
     * @return
     */
    @Override
    public CpFollowPlanVO selectFollowPlanInfoById(String cpFollowPlanId) {
        return followPlanMapper.selectFollowPlanInfoById(cpFollowPlanId);
    }
}
